#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
'''
@File    :   bric_acs.py
@Time    :   2020/11/27
@Author  :   wenke wang
@Version :   1.0
@Desc    :   BRIC-ACS评估模型
'''

# here put the import lib
import math
from decimal import Decimal
from bric_acs_eval_param import BricAcsEvalParam

def evaluate(param):
    """
    BRIC-ACS评估模型
    """
    precision = Decimal("0.00")
    # TG log10
    tg_log10 = math.log10(param.tg)
    tg_log10 = Decimal(str(tg_log10)).quantize(precision)
    # LDL-C log10
    ldlc_log10 = math.log10(param.ldlc)
    ldlc_log10 = Decimal(str(ldlc_log10)).quantize(precision)
    # gender
    gender_val = 1 if param.gender == "F" else 0
    bric_score = Decimal("64.49") + Decimal("3.06") * Decimal(gender_val) + Decimal("8.97") * param.pu \
            + Decimal("5.56") * param.hy - Decimal("2.62") * param.mvd + Decimal("8.47") * param.ct \
            - Decimal("0.72") * param.bmi - Decimal("0.12") * param.hb - Decimal("11.97") * tg_log10 \
            - Decimal("5.13") * ldlc_log10

    bric_score = bric_score.quantize(precision)
    if bric_score > Decimal("40.00") and bric_score <= Decimal("60.00"):
        risk = "high"
    elif bric_score > Decimal("20.00") and bric_score <= Decimal("40.00"):
        risk = "middle"
    else:
        risk = "low"

    return { "score": str(bric_score), "risk": risk }

if __name__ == "__main__":
    param = BricAcsEvalParam('M', 170, 55, 0, 0, 0, 0, 86, 75, 34)
    result = evaluate(param)
    print(result)


    